package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Bin;
import com.ruoyi.system.service.IBinService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库位档案Controller
 * 
 * @author ruoyi
 * @date 2025-10-16
 */
@RestController
@RequestMapping("/system/bin")
public class BinController extends BaseController
{
    @Autowired
    private IBinService binService;

    /**
     * 查询库位档案列表
     */
    @PreAuthorize("@ss.hasPermi('system:bin:list')")
    @GetMapping("/list")
    public TableDataInfo list(Bin bin)
    {
        startPage();
        List<Bin> list = binService.selectBinList(bin);
        return getDataTable(list);
    }

    /**
     * 导出库位档案列表
     */
    @PreAuthorize("@ss.hasPermi('system:bin:export')")
    @Log(title = "库位档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bin bin)
    {
        List<Bin> list = binService.selectBinList(bin);
        ExcelUtil<Bin> util = new ExcelUtil<Bin>(Bin.class);
        util.exportExcel(response, list, "库位档案数据");
    }

    /**
     * 获取库位档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bin:query')")
    @GetMapping(value = "/{binId}")
    public AjaxResult getInfo(@PathVariable("binId") String binId)
    {
        return success(binService.selectBinByBinId(binId));
    }

    /**
     * 新增库位档案
     */
    @PreAuthorize("@ss.hasPermi('system:bin:add')")
    @Log(title = "库位档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bin bin)
    {
        return toAjax(binService.insertBin(bin));
    }

    /**
     * 修改库位档案
     */
    @PreAuthorize("@ss.hasPermi('system:bin:edit')")
    @Log(title = "库位档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bin bin)
    {
        return toAjax(binService.updateBin(bin));
    }

    /**
     * 删除库位档案
     */
    @PreAuthorize("@ss.hasPermi('system:bin:remove')")
    @Log(title = "库位档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{binIds}")
    public AjaxResult remove(@PathVariable String[] binIds)
    {
        return toAjax(binService.deleteBinByBinIds(binIds));
    }
}
